/* SPF (Sender Policy Framework) implementation.

Copyright (c) 2007 Roberto Alsina <ralsina@kde.org>
This module is free software, and you may redistribute it and/or modify
it under the same terms as Python itself, so long as this copyright message
and disclaimer are retained in their original form.

IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

For more information about SPF, a tool against email forgery, see
http://www.openspf.org/

For new versions check out http://code.google.com/p/raspf

*/

#include <stdio.h>
#include <getopt.h>

#include "raspf.h"


int main(int argc, char **argv)
{
    int c;
    int digit_optind = 0;

    char *ip="";
    char *helo="";
    char *sender="";

    while (1)
    {
        int this_option_optind = optind ? optind : 1;
        int option_index = 0;
        static struct option long_options[] = {
            {"sender", 1, 0, 0},
            {"helo", 1, 0, 0},
            {"ip", 1, 0, 0},
            {0, 0, 0, 0}
        };
        c = getopt_long (argc, argv, "s:h:i:",
                         long_options, &option_index);
        if (c == -1)
            break;

        switch (c)
        {
        case 0:
            switch(option_index)
            {
            case 0:
                sender=optarg;
                break;
            case 1:
                helo=optarg;
                break;
            case 2:
                ip=optarg;
                break;
            }
            break;
        case 's':
            sender=optarg;
            break;
        case 'h':
            helo=optarg;
            break;
        case 'i':
            ip=optarg;
            break;
        }
    }

    printf ("Checking SPF with:\n\nsender:\t%s\nhelo:\t%s\nip:\t%s\n\n",
            sender,helo,ip);

    spf_init();
    spf_response r=spf_check(ip,sender,helo,0,0);
    printf ("\nresponse:\t%s\ncode:\t\t%d\nexplanation:\t\t%s\n",
            r.response,r.code,r.explanation);

    spf_close();

    free (r.response);
    free (r.explanation);

    exit(0);

}
